/*
 * SuperBlock.h
 *
 *  Created on: 28 Apr 2011
 *      Author: Marc Kampherbeek
 */

#ifndef SUPERBLOCK_H_
#define SUPERBLOCK_H_

#include "Block.h"
#include "FreeBlock.h"
#include "Inode.h"

class SuperBlock : public Block{
private:
	int isize; 				//size in blocks in i-list
	int fsize; 				//size in blocks on volume
	FreeBlock* freeblock; 	//free block list
	int ninode; 			//number of inodes in inode list
	int inodes[100]; 		//inode list (inode numbers)
	byte flock; 			//free list manipulation lock
	byte ilock; 			//inode list manipulation lock
	byte fmod; 				//super block modification indicator
	byte ronly; 			//read-only flag
	long time; 				//last modification time
	long tfree; 			//total free blocks
	int tinode; 			//total free inodes
	int m; 					//interleave factor
	int n; 					//" " (cylinder size)
	char fname[6]; 			//file system name
	char fpack[6]; 			//fs pack name
public:
	SuperBlock(int i, byte* b) : Block(i, b){ parseSuperBlock(); };
	virtual ~SuperBlock();

	int getISize(){ return isize; };
	int getFSize(){ return fsize; };
	int getNFree(){ return freeblock->getSize(); };
	long getFreeBlockAddress(){ return freeblock->get(); };
	FreeBlock* getFreeBlock(){ return freeblock; };
	int getNInode(){ return ninode; };
	int* getInodes(){ return inodes; };
	int getInode(int i){ return inodes[i]; };
	byte getFLock(){ return flock; };
	byte getILock(){ return ilock; };
	byte getFMod(){ return fmod; };
	byte getROnly(){ return ronly; };
	long getTime(){ return time; };
	long getTFree(){ return tfree; };
	int getTInode(){ return tinode; };
	int getM(){ return m; };
	int getN(){ return n; };
	char* getFName(){ return fname; };
	char* getFPack(){ return fpack; };

	Inode* getFreeInode();
	void scanForFreeInodes();
	void parseSuperBlock();
	void writeFreeInodeList();
	void print();
};

#endif /* SUPERBLOCK_H_ */
